<template>
    <nav class="navbar navbar-expand-lg bg-body-tertiary nb">
    <div class="container">
      <span class="navbar-brand">SQL学习系统</span>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarText">
        <ul class="navbar-nav me-auto mb-2 mb-lg-0">
          <li class="nav-item">
            <router-link :class="router_name == 'systemSet' ? 'nav-link active' : 'nav-link' " aria-current="page" :to="{name: 'systemSet'}">系统题集</router-link>
           
          </li>
          <li class="nav-item">
            <router-link :class="router_name == 'myClass' ? 'nav-link active' : 'nav-link' " aria-current="page" :to="{name: 'myClass'}">我的班级</router-link>
          </li>
          <li class="nav-item">
            <span :class="router_name == 'classSet' ? 'nav-link active' : 'nav-link' " aria-current="page">其他</span>
          </li>
        </ul>
        <div>
              <span class="navbar-brand" style="margin-right: 80px; font-size: 21px; font-weight: bold; color:yellowgreen">{{ now }}</span>
        </div>
        <span class="navbar-brand wel">欢迎登录，{{ $store.state.user.username }}同学</span>
        <ul class="navbar-nav">
          <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            <!-- {{$store.state.user.username}} -->
              学生信息
          </a>
            <ul class="dropdown-menu">
              <!-- <li><a class="dropdown-item" href="#">我的信息</a></li> -->
              <li><span class="dropdown-item" href="#">{{ $store.state.user.username }}</span></li>
              <li><router-link class="dropdown-item" :to="{name: 'login'}" @click="logout">退出登录</router-link></li>
            </ul>
          </li>
        </ul>

      </div>
    </div>
  </nav>
</template>
   
<script>
   
  import {useStore} from 'vuex'; 
  import {ref} from 'vue';
  import  formateDate from '@/utils/GetCurrentTime';

  export default{
        name : "NavBar",
        setup(){
          const store = useStore();
          let now = ref('');

          const getTime = (now) => {
            setInterval( () => {
              now.value = formateDate(new Date());
            }, 100);
          };

          getTime(now);

          const logout = () =>{
            store.dispatch("logout");
          };


          return {
            logout,
            getTime,
            now,
          }
        }
  }
</script>
   
<style scoped>
   a{
      text-decoration: none;
   }
   .nb{
      background-color: #e3f2fd;
   }
</style>